<template>
  <div class="global_company_info main_white marginTop10">
    <div class="mainua_form marginTop20 paddingTop0">
      <div class="main_ti">
        <div class="radio_box" v-if="companyInfo.model == 3">
          <el-radio-group v-model="form.wx_pay">
            <el-radio :label="0">银联支付</el-radio>
            <el-radio :label="1">微信支付</el-radio>
          </el-radio-group>
        </div>
        <div v-if="form.wx_pay == 0 || companyInfo.model == 2">
          <el-form
            :inline="false"
            :model="form"
            class="demo-form-inline"
            ref="userListFrom"
            label-width="140px"
          >
            <el-form-item label="银联appid：" prop="site_title">
              <el-input
                v-model="form.union_appId"
                placeholder="请输入银联appid"
              ></el-input>
            </el-form-item>
            <el-form-item label="银联appkey：" prop="site_phone">
              <el-input
                v-model="form.union_appKey"
                placeholder="请输入银联appkey"
              ></el-input>
            </el-form-item>
            <el-form-item label="银联md5密钥：" prop="site_title">
              <el-input
                v-model="form.union_md5Key"
                placeholder="请输入银联md5密钥"
              ></el-input>
            </el-form-item>

            <el-form-item label="银联商户号：" prop="company_address">
              <el-input
                v-model="form.union_mid"
                placeholder="请输入银联商户号"
              ></el-input>
            </el-form-item>
            <el-form-item label="银联终端号：" prop="receive_man">
              <el-input
                v-model="form.union_tid"
                placeholder="请输入银联终端号"
              ></el-input>
            </el-form-item>
            <el-form-item label="银联来源编号：" prop="receive_mobile">
              <el-input
                v-model="form.union_from_code"
                placeholder="请输入银联来源编号"
              ></el-input>
            </el-form-item>
            <el-form-item label=" ">
              <el-button type="primary" @click="preservation" v-repeatClick
                >保存</el-button
              >
            </el-form-item>
          </el-form>
        </div>
        <div v-if="form.wx_pay == 1 && companyInfo.model == 3">
          <el-form
            :inline="false"
            :model="form"
            class="demo-form-inline"
            ref="userListFrom"
            label-width="140px"
          >
            <el-form-item label="微信key：" prop="site_title">
              <el-input
                v-model="form.wx_key"
                placeholder="请输入微信key"
              ></el-input>
            </el-form-item>
            <el-form-item label="微信machId：" prop="site_title">
              <el-input
                v-model="form.wx_machId"
                placeholder="请输入微信machId"
              ></el-input>
            </el-form-item>
            <el-form-item label=" ">
              <el-button type="primary" @click="preservation" v-repeatClick
                >保存</el-button
              >
            </el-form-item>
          </el-form>
        </div>

        <div class="clearfix"></div>
        <div class="newConBox_p100 paddingBottom10" id="newConBox">
          <div class="newConBox_h32">
            <div
              :class="[
                'mainua_an newConBox ',
                { on: searchBarFixed },
                { marginLeft5: !searchBarFixed },
              ]"
            ></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { uploadPath } from "@/api/currency";
import { setting_info } from "@/api/global/globalSystem";
import { setting_company } from "@/api/currency";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";

export default {
  computed: {
    ...mapGetters(["avatar", "companyInfo"]),
  },
  data() {
    return {
      // 上传图片
      uploadPath,
      // 搜索
      form: {
        // 银联
        union_appId: "",
        union_appKey: "",
        union_mid: "",
        union_tid: "",
        union_from_code: "",
        union_md5Key: "",
        // 微信
        wx_key: "",
        wx_machId: "",
        wx_pay: 0,
      },
      radio: 0,
      // model==2,银联支付,model==3两个
      // 监听滚动
      searchBarFixed: false,
    };
  },
  mounted() {
    window.addEventListener("scroll", this.handleScroll);
  },
  destroyed() {
    window.removeEventListener("scroll", this.handleScroll);
  },
  methods: {
    // 监听滚动
    handleScroll() {
      let scrollTop =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop;
      scrollTop + document.documentElement.clientHeight >
      document.getElementById("newConBox").offsetTop + 300
        ? (this.searchBarFixed = false)
        : (this.searchBarFixed = true);
    },
    // 上传图片-成功
    handSuccess(res, file, fileList) {
      // console.log(res, file, fileList);
      this.form.site_logo = res.path;
      this.form.pic = res.src;
    },
    // 保存
    preservation() {
      this.$refs["userListFrom"].validate((valid) => {
        if (valid) {
          let sz = JSON.parse(JSON.stringify(this.form));
          let { pic, ...form } = sz;
          let data = Object.assign(
            apiUrl().name,
            form
          );
          setting_company(data).then((res) => {
            if (res.errcode == 0) {
              this.$message({
                message: "保存成功",
                type: "success",
              });
            } else {
              this.$message.error(res.errmsg);
            }
          });
        }
      });
    },
    // 基本信息
    setting_info() {
      let data = Object.assign(
        apiUrl().name
      );
      setting_info(data).then((res) => {
        if (res.errcode == 0) {
          if (res.data.info) {
            this.form.union_appId = res.data.info.union_appId;
            this.form.union_md5Key = res.data.info.union_md5Key;
            this.form.union_appKey = res.data.info.union_appKey;
            this.form.union_mid = res.data.info.union_mid;
            this.form.union_tid = res.data.info.union_tid;
            this.form.union_from_code = res.data.info.union_from_code;
            this.form.wx_machId = res.data.info.wx_machId;
            this.form.wx_key = res.data.info.wx_key;
            this.form.wx_pay = res.data.info.wx_pay;
          }
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
  },
  created() {
    // 基本信息
    this.setting_info();
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";

.global_company_info {
  .mainua_form {
    .mainua_an {
      /deep/.el-form-item__content {
        margin-left: 0px !important;
      }
      .reset {
        background: $subActive;
        color: $menuText;
        border-color: $subActive;

        &:hover,
        &:focus {
          border-color: $menuActiveText;
          color: $menuActiveText;
        }
      }
    }
  }
  padding: 10px 10px 10px 10px;
  margin: 0 15px 0 15px;
  /deep/.el-input {
    width: 400px;
  }
  /deep/.el-textarea__inner {
    width: 600px !important;
    height: 200px;
  }
  .global_cu {
    font-size: 12px;
    color: #eb0a0a;
    margin-top: -10px;
    padding-left: 7px;
  }
}
.radio_box {
  padding-left: 80px;
  padding-bottom: 18px;
}
</style>
